{extend name="normal_base" /}
{block name="navigation"}{/block}
{block name="css"}
<style>
    .layui-form-item {
        width: 100%;
    }

    .layui-table td {
        padding: 5px;
    }

    .layui-form-label {
        width: 100px;
    }

    #service_content_div{
        width: 80%;
    }

</style>
{/block}
{block name="body"}
<div class="x-body">
    <form class="layui-form" id="from_id" method="POST" action="{:url('add')}">
        <div class="layui-form-item">
            <label for="software_name" class="layui-form-label">
                <span class="x-red">*</span>&nbsp;软件名称：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="software_name" name="software_name" value="" autocomplete="off" class="layui-input" lay-verify="required|m_software_name">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <div class="layui-input-block">
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    增加
                </button>

                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
{/block}

{block name="script"}
<script src="__JS__/jquery.raty.js"></script>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form

        //自定义验证规则
        form.verify({
            m_software_name:function (value) {
                //验证长度是否超出限制,50个字
                if(value.length > 255){
                    return '软件名称长度超出限制，最多 255 个字';
                }
            }
        });

        //监听提交
        form.on('submit(add)', function(data){
            $("#from_id").ajaxSubmit({
                beforeSubmit:function () {
                    //表单提交前
                },
                success:function (data) {
                    //console.log(JSON.stringify(data));
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:5,time:1500});
                    } else {
                        layer.alert("添加成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新父层页面
                            parent.location.replace(parent.location.href);
                        });
                    }
                }
            });
            return false;
        });

        /*代码转大写*/
        $('#code').blur(function () {
            $('#code').val($('#code').val().toUpperCase());
        });
    });


</script>
{/block}